|
These two methods allow conversion between a C# byte array and string, and vice versa. Handy in dealing with COM objects and some .Net Providers (IBM CWBX, EventLog and so on). String to byte array: public static byte[]
StrToByteArray(string
str)
{ System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); return encoding.GetBytes(str); } Byte array to string: public static string ByteArrayToStr(byte[]
byteArray)
{ System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); return encoding.GetString(byteArray); }
You may also like
Leave a ReplyClick here to cancel reply.
|
![Add `String to byte[] and byte[] to String` to Digg Add `String to byte[] and byte[] to String` to Digg](String%20to%20byte[]%20and%20byte[]%20to%20String%20-%20C%23%20Tutorials_files/digg.png)
![Add `String to byte[] and byte[] to String` to Del.icio.us Add `String to byte[] and byte[] to String` to Del.icio.us](String%20to%20byte[]%20and%20byte[]%20to%20String%20-%20C%23%20Tutorials_files/delicious.png)
![Add `String to byte[] and byte[] to String` to Technorati Add `String to byte[] and byte[] to String` to Technorati](String%20to%20byte[]%20and%20byte[]%20to%20String%20-%20C%23%20Tutorials_files/technorati.png)
![Add `String to byte[] and byte[] to String` to Stumble Upon Add `String to byte[] and byte[] to String` to Stumble Upon](String%20to%20byte[]%20and%20byte[]%20to%20String%20-%20C%23%20Tutorials_files/stumbleupon.png)
![Add `String to byte[] and byte[] to String` to Google Bookmarks Add `String to byte[] and byte[] to String` to Google Bookmarks](String%20to%20byte[]%20and%20byte[]%20to%20String%20-%20C%23%20Tutorials_files/google.png)
![Add `String to byte[] and byte[] to String` to Facebook Add `String to byte[] and byte[] to String` to Facebook](String%20to%20byte[]%20and%20byte[]%20to%20String%20-%20C%23%20Tutorials_files/facebook.png)
![Add `String to byte[] and byte[] to String` to Twitter Add `String to byte[] and byte[] to String` to Twitter](String%20to%20byte[]%20and%20byte[]%20to%20String%20-%20C%23%20Tutorials_files/twitter.png)
